#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<math.h>
int maxProfit(int* prices, int pricesSize) {

    int dp0 = 0, dp1 = -prices[0];
    for (int i = 1; i < pricesSize; ++i) {
        int newDp0 = fmax(dp0, dp1 + prices[i]);
        int newDp1 = fmax(dp1, dp0 - prices[i]);
        dp0 = newDp0;
        dp1 = newDp1;
    }
    return dp0;
}
